package com.bristua.mall.common.bean;

import com.github.pagehelper.Page;

import java.util.List;

/**
 * Created by Administrator on 2018/9/25.
 */
public class PageBean<T> {
    private long totalCount; // 总记录数
    private int totalPage; // 总页数
    private int pageNo; // 第几页
    private int pageSize; // 页面大小
    private List<T> list; // 结果集

    public long getTotalCount() {
        return totalCount;
    }

    public void setTotalCount(long totalCount) {
        this.totalCount = totalCount;
    }

    public int getTotalPage() {
        return totalPage;
    }

    public void setTotalPage(int totalPage) {
        this.totalPage = totalPage;
    }

    public int getPageNo() {
        return pageNo;
    }

    public void setPageNo(int pageNo) {
        this.pageNo = pageNo;
    }

    public int getPageSize() {
        if(pageSize>totalCount){
            return Integer.valueOf(totalCount+"");
        }
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public List<T> getList() {
        return list;
    }

    public void setList(List<T> list) {
        this.list = list;
    }

    public PageBean(List<T> list) {
        if (list instanceof Page) {
            Page<T> page = (Page<T>) list;
            this.totalCount = page.getTotal();
            this.totalPage = page.getPages();
            this.pageNo = page.getPageNum();
            this.pageSize = page.getPageSize();
            this.list = page;
        }
    }
}
